package org.hawk.gwt.ppc.utils;

import junit.framework.TestCase;

public class PatternTestCase extends TestCase {
	public void testAntExact(){
		assertTrue(new AntPattern("test").match("test"));
		assertTrue(new AntPattern("aaa.bbb.ccc").match("aaa.bbb.ccc"));
		assertFalse(new AntPattern("test").match("tept"));
		assertFalse(new AntPattern("aaa.bbb.ccc").match("aaa.bbb.ccc.ddd"));
		assertFalse(new AntPattern("aaa.bbb.ccc").match("aaa.bbb"));
	}

	public void testSimple(){
		assertTrue(new AntPattern("*").match("test"));
		assertFalse(new AntPattern("*").match("test.aaa"));
		assertFalse(new AntPattern("aaa.*.bbb").match("aaa.test"));
		assertTrue(new AntPattern("aaa.*.bbb").match("aaa.test.bbb"));
		assertTrue(new AntPattern("aaa.*.*.x").match("aaa.test.bbb.x"));
	}
	
	public void testComplex(){
		assertTrue(new AntPattern("**").match("test.aaa.bbb.ccc.ddd"));
		assertTrue(new AntPattern("**").match("test"));
		assertTrue(new AntPattern("aaa.**").match("aaa.test"));
		assertTrue(new AntPattern("aaa.**").match("aaa.test.rrr"));
		assertFalse(new AntPattern("aaa.**").match("bbb.test.rrr"));
		assertTrue(new AntPattern("**.test").match("test"));
		assertFalse(new AntPattern("**.test2").match("test"));
		assertTrue(new AntPattern("**.test2").match("aaa.ss.dd.ee.ff.test2"));
	}
	
	public void testMisc(){
		assertTrue(new AntPattern("*.jsp").match("test.jsp"));
		assertFalse(new AntPattern("*.jsp").match("test.jsp.aaa"));
		assertTrue(new AntPattern("a*x*1").match("alexey1"));
		assertTrue(new AntPattern("a*x*1").match("alexandr1"));
		assertTrue(new AntPattern("a*x*").match("alexandr1"));
		assertTrue(new AntPattern("a*x*").match("alex"));
		assertFalse(new AntPattern("a*m*x").match("asxdmr"));
		assertTrue(new AntPattern("a*md.*.js").match("asmd.index.js"));
	}
	
	public void testIssue5(){
		assertTrue(new AntPattern("aaa.bbb**").match("aaa.bbb.ccc.ddd"));
		assertTrue(new AntPattern("aaa.bbb**ddd").match("aaa.bbb.ccc.ddd"));
		assertTrue(new AntPattern("aaa.bbb**ddd").match("aaa.bbb.ccc.ddd"));
		assertTrue(new AntPattern("aaa.bb**ddd").match("aaa.bbb.ccc.ddd"));
		assertTrue(new AntPattern("aaa.bb**").match("aaa.bbb.ccc.ddd"));
		assertTrue(new AntPattern("aaa.**bb.ccc").match("aaa.bbb.ccc"));
		assertTrue(new AntPattern("aaa.**bb.ccc").match("aaa.ddd.bbb.ccc"));
		assertFalse(new AntPattern("aaa.b**b.ccc").match("aaa.ddd.bbb.ccc"));
		assertTrue(new AntPattern("aaa.b**b.ccc").match("aaa.bb.bb.a.c.bb.ccc"));
		assertFalse(new AntPattern("**aa.bbb").match("aaa.bbb.ccc.ddd"));
		assertTrue(new AntPattern("**aa.bbb").match("aaa.bbb"));
		assertTrue(new AntPattern("**aa.bbb").match("ccc.ddd.aaa.bbb"));
	}
}
